<?php
include 'include/functions.php';

?>
<!DOCTYPE html PUBLIC "-//W3C//Dtd html 4.01 Transitional//EN"
"http://www.w3.org/tr/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/MAIN.dwt.php" codeOutsideHTMLIsLocked="false" -->
  <head>
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>JoshHughes.com NFL Football Pool</title>
    <!-- InstanceEndEditable -->
	<link rel="stylesheet" href="css/football.css" type="text/css">
    <script src="scripts/prototype.js" type="text/javascript"></script>
	<script src="scripts/scriptaculous.js" type="text/javascript"></script>
	<script type="text/javascript">
	// Dynamic Iframe loader
	function loadIframe(theFrame, theURL) {
		document.getElementById(theFrame).src=theURL;
	}
	
	// resizes Iframe according to content
	function resizeMe(obj){ 
	docHeight = mainContent.document.body.scrollHeight
	 obj.style.height = docHeight + 'px'
	 } 
	</script>
    <!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
  </head>
<body>
<div id="pagewidth" >
	<div id="header" >
			
				<?PHP include_once("layout/header.html"); ?>
	</div>
			<div id="wrapper" class="clearfix" > 
			<div id="maincol" >

			<!-- InstanceBeginEditable name="Contents" -->

				<?php
				
				if (isset($q))
				{
					$pool_adm_Email = "Football@joshhughes.com";
					
					//Connect To Database
					dbConnect();
					
					$sql = "SELECT * FROM NFLUsers WHERE Username='$_POST[q]' OR Email='$_POST[q]'";
					$result = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
					$count = mysql_num_rows($result);
					
					if ($count == 1)
					{
						$sql="SELECT Username, Password, Fname, Email FROM NFLUsers WHERE Username='$_POST[q]' OR Email='$_POST[q]'";
						$result=mysql_query($sql);
						while ($row = mysql_fetch_array($result))
						{
							echo "<p>A Password reminder has been sent to you by Email to <b>$row[Email]</b>.</p>\n<p>If you continue to receive problems, please feel free to Email us at <a href=\"mailto:$pool_adm_Email\">$pool_adm_Email</a>.</p>\n";
							$to = $row[Email];
							$subject = "Your Password Reminder";
							$headers = "From: Football Pool <$pool_adm_Email>";
							$message = "$row[Fname],\n\nSomeone has requested that a password reminder be sent to you for your account with the JoshHughes.com Football Pool.\n\nPlease find confirmation of your log in details as follows:\nUsername: $row[Username]\nPassword: $row[Password]\n\nIf you continue to receive problems, please Email $pool_adm_Email.\n\nRegards\n\nFootball Pool Administrator\nhttp://football.joshhughes.com";
							mail($to, $subject, $message, $headers);
						}
					}
					else
					{
						echo "<p>The query <b>$_POST[q]</b> could not be matched as a Username nor Email address.</p>\n<p>Please <a href=\"javascript:history.go(-1)\">go back</a> and try again.</p>\n";
					}
				}
				else
				{
					?>
						<form action="<?= $PHP_SELF; ?>" method="post">
						<table bgcolor="#346FB7" cellpadding="3" cellspacing="0" bordercolor="#000000" border="0" width="300">
							<tr bordercolor="#346FB7">
								<td bordercolor="#346FB7">
									<table bgcolor="#FFFFFF">
									<tr>
										<td>
											<p>Please enter the Username or Email address you registered with:</p>
										</td>
									<tr>
									<tr>
										<td>
											<input type="text" size="20" name="q" value=""/>
										</td>
									<tr>
									<tr>
										<td>
											<input type="Submit" value="Submit" />
										</td>
									<tr>
									</TABLE>
								</td>
							</tr>
						</table></form>
					<?
				}
				?>

			<!-- InstanceEndEditable -->
			
			</div>
			<div id="leftcol" >
			
				<?PHP include_once("layout/left_column.php"); ?>
		
			</div>
			
		</div>
		
		<div id="footer" >
		
			<?PHP include_once("layout/footer.html"); ?>
			
		</div>
</div>
</body>
<!-- InstanceEnd --></html>